local que_qieyun = fk.CreateSkill {
    name = "que_qieyun",
    anim_type = "offensive",
}

Fk:loadTranslationTable {
    ["que_qieyun"] = "窃运",
    [":que_qieyun"] = "拥有占卜效果的其他角色回合开始时，其可以交给你两张牌，然后选择与一名除你外的其他角色<a href='zhanbu_jh'>交换占卜效果</a>。",

    ["zhanbu_jh"] = "交换效果：并非仅交换标记和对应触发效果，若目标效果中包含延迟效果，也会一并转移，如：轮回，休生；注意特殊占卜，强运，转移该效果会立刻触发一次效果，被转移走强运的角色会因此弃牌",

}

que_qieyun:addEffect(fk.TurnStart, {
    anim_type = "offensive",
    can_trigger = function(self, event, target, player, data)
        local id = table.find(player.room.alive_players, function(p)
            return p:hasSkill(que_qieyun.name)
        end)
        return target == player and not player:hasSkill("que_zhanming") and player:getMark("@que_zhanming") ~= 0 and id and
            player:getHandcardNum() > 1 and
            #table.filter(player.room:getOtherPlayers(id, false), function(p)
                return p:getMark("@que_zhanming") ~= 0 and p ~= player
            end) > 0
    end,
    on_cost = function(self, event, target, player, data)
        local room = player.room
        local id = table.find(player.room.alive_players, function(p)
            return p:hasSkill(que_qieyun.name)
        end)
        local to, cards = room:askToChooseCardsAndPlayers(player, {
            min_card_num = 2,
            max_card_num = 2,
            min_num = 1,
            max_num = 1,
            targets = table.filter(player.room:getOtherPlayers(player, false), function(p)
                return p:getMark("@que_zhanming") ~= 0 and p ~= id
            end),
            skill_name = que_qieyun.name,
            prompt = "窃运：请选择要交换占卜效果的角色",
            cancelable = true,
            will_throw = true,
        })
        if #to > 0 and #cards > 0 then
            event:setCostData(self, { tos = to, cards = cards })
            return true
        end
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local id = table.find(player.room.alive_players, function(p)
            return p:hasSkill(que_qieyun.name)
        end)
        local to = event:getCostData(self).tos[1]
        local markto = to:getMark("@que_zhanming")
        local markfrom = player:getMark("@que_zhanming")
        room:moveCardTo(event:getCostData(self).cards, Player.Hand, id, fk.ReasonGive, que_qieyun.name, nil, false,
            player)
        room:setPlayerMark(to, "@que_zhanming", markfrom)
        room:setPlayerMark(player, "@que_zhanming", markto)
        if markto == "zm_tiaoguo" then
            room:setPlayerMark(to, "zm_tiaoguo_phase", 0)
            room:setPlayerMark(player, "zm_tiaoguo_phase", { Player.Judge, Player.Discard })
        end
        if markto == "zm_xiusheng" then
            room:setPlayerMark(to, "zm_tiaoguo_phase", 0)
            room:setPlayerMark(player, "zm_tiaoguo_phase", { Player.Play })
            room:addPlayerMark(player, MarkEnum.AddMaxCards, 1)
            room:removePlayerMark(to, MarkEnum.AddMaxCards, 1)
        end
        if markfrom == "zm_tiaoguo" then
            room:setPlayerMark(player, "zm_tiaoguo_phase", 0)
            room:setPlayerMark(to, "zm_tiaoguo_phase", { Player.Judge, Player.Discard })
        end
        if markfrom == "zm_chenmeng" then
            room:setPlayerMark(player, "zm_tiaoguo_phase", 0)
            room:setPlayerMark(to, "zm_tiaoguo_phase", { Player.Play, Player.Discard })
        end
        if markfrom == "zm_xiusheng" then
            room:setPlayerMark(player, "zm_tiaoguo_phase", 0)
            room:setPlayerMark(to, "zm_tiaoguo_phase", { Player.Play })
            room:addPlayerMark(to, MarkEnum.AddMaxCards, 1)
            room:removePlayerMark(player, MarkEnum.AddMaxCards, 1)
        end
        if markto == "zm_qiangyun" then
            room:throwCard(table.random(to:getCardIds("h"), math.random(1, 3)), "que_zhanming", to, to)
            player:drawCards(math.random(1, 3), "que_zhanming")
        end
        if markfrom == "zm_qiangyun" then
            room:throwCard(table.random(player:getCardIds("h"), math.random(1, 3)), "que_zhanming", player, player)
            to:drawCards(math.random(1, 3), "que_zhanming")
        end
    end,
})

return que_qieyun
